import VueRouter from 'vue-router';

import riskAssessmentRouters from './modules/risk-assessment';
import businessManagement from './modules/business-management';

// 存放动态路由
// eslint-disable-next-line import/no-mutable-exports
export const asyncRouterList = [...riskAssessmentRouters, ...businessManagement];

// 存放固定的路由
const defaultRouterList = [
  {
    path: '/login',
    name: 'login',
    component: () => import('@/pages/login/index.vue'),
  },
  {
    path: '*',
    // redirect: '/dashboard',
    // redirect: '/login',
    redirect: '/risk-assessment',
  },
  {
    path: '/dashboard',
    name: 'dashboard',
    component: () => import('@/pages/dashboard/index.vue'),
    redirect: '/dashboard/content',
    children: [
      // 个人账号--先放在这
      {
        path: 'account',
        name: 'personalAccount',
        component: () => import('@/pages/dashboard/components/personalAccount.vue'),
        meta: { routeType: 'risk' },
      },
      {
        path: 'content',
        name: 'dashContent',
        component: () => import('@/pages/dashboard/components/dashContent.vue'),
        meta: { routeType: 'risk' },
      },
    ],
  },
  ...asyncRouterList,
];
const createRouter = () =>
  new VueRouter({
    routes: defaultRouterList,
    scrollBehavior() {
      return { x: 0, y: 0 };
    },
  });

const router = createRouter();

export function resetRouter() {
  const newRouter = createRouter();
  router.match = newRouter.match; // reset router
}
export default router;
